package cn.wolfcode.luowowo.advice;

import cn.wolfcode.luowowo.common.exception.LogicException;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

/**
 * @ControllerAdvice
 * 对请求方法处理签  处理后动态增加功能
 *
 * 运用场景 统一异常处理
 */

@ControllerAdvice
public class CommonExceptionHandler {
    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object LogicExp(Exception e) throws IOException{
        e.printStackTrace();
        return new AjaxResult(false,e.getMessage());
    }
    //系统异常处理
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Object runTimeExp(Exception e) throws IOException{
        e.printStackTrace();
        return new AjaxResult(false,"系统异常,请联系管理员");
    }

}
